﻿package fj.ui
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import fj.events.FJImageTransformRotateEvent;
	import fj.events.FJImageTransformMoveEvent;
	import fj.events.FJImageTransformScaleEvent;
	
	public class FJImageTransform extends MovieClip
	{
		public var area:MovieClip;
		
		private var _conteudo:MovieClip;
		private var _selector:FJImageTransformSelector;
		
		public function FJImageTransform():void
		{
			_conteudo = getChildByName( "conteudo" ) as MovieClip;
			_selector = getChildByName( "selector" ) as FJImageTransformSelector;
			
			_selector.adjust( 223.5, 323.3 );
			
			_selector.addEventListener( FJImageTransformRotateEvent.ROTATE, selectorRotate );
			_selector.addEventListener( FJImageTransformScaleEvent.SCALE, selectorScale );
			_selector.addEventListener( FJImageTransformMoveEvent.MOVE, selectorMove );
			_selector.addEventListener( MouseEvent.MOUSE_DOWN, selectorDown );
			
			area.addEventListener( MouseEvent.CLICK, areaClick );
		}
		private function selectorRotate( e:FJImageTransformRotateEvent ):void
		{
			_conteudo.rotation = e.rotation;
		}
		private function selectorScale( e:FJImageTransformScaleEvent ):void
		{
			_conteudo.scaleX = _conteudo.scaleY = e.scale;
		}
		private function selectorMove( e:FJImageTransformMoveEvent ):void
		{
			_conteudo.x = e.x;
			_conteudo.y = e.y;
		}
		private function selectorDown( e:MouseEvent ):void
		{
			_selector.show();
		}
		private function areaClick( e:MouseEvent ):void
		{
			_selector.hide();
		}
	}
}